package com.ustb.springboot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ustb.springboot.common.utils.R;
import com.ustb.springboot.common.utils.TokenUtil;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;


import com.ustb.springboot.dao.QuestionRadioDao;
import com.ustb.springboot.entity.QuestionRadioEntity;
import com.ustb.springboot.service.QuestionRadioService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;


@Service("questionRadioService")
public class QuestionRadioServiceImpl extends ServiceImpl<QuestionRadioDao, QuestionRadioEntity> implements QuestionRadioService {

    @Resource
    private QuestionRadioDao questionRadioDao;

    @Override
    public R save(HttpServletRequest request, QuestionRadioEntity questionRadio) {
        //userId
        questionRadio.setUserId(TokenUtil.getId(request));
        return this.save(questionRadio) ? R.ok(20000, "保存成功") : R.error(2000, "保存失败");

    }

    @Override
    public R remove(Map<String, Object> body) {

        QueryWrapper<QuestionRadioEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", body.get("id"));
        return 1 == questionRadioDao.delete(queryWrapper) ? R.ok(20000, "删除成功！") : R.error(2000, "删除失败！");
    }

    @Override
    public List<QuestionRadioEntity> queryQuestionRadioWithId(Map<String, Object> body) {
        QueryWrapper<QuestionRadioEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", body.get("question_id"));
        return questionRadioDao.selectList(queryWrapper);
    }

}